home *** CD-ROM | disk | FTP | other *** search
- Path: news.xnet.com!kato
- From: kato@flood.xnet.com (Ian Curtis)
- Newsgroups: comp.lang.c
- Subject: Re: Leap Years
- Date: 3 Mar 1996 20:43:59 GMT
- Organization: XNet - A Full Service Internet Provider - (708) 983-6064
- Message-ID: <4hd0af$r6k@flood.xnet.com>
- References: <8BA8405.02C70020E1.uuout@sourcebbs.com> <4h6ara$mu@netnews1.apci.com>
- NNTP-Posting-Host: cyclone.xnet.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Martin Ward (wardmw@apci.com) wrote:
- : david.mohorn@sourcebbs.com (DAVID MOHORN) typed:
-
- : >How do you feature out leap years? If its evenly divisible by 400 and
- : >4?
-
- The year does not have to be evenly divisible by 400 to qualify as a leap
- year. This year is a leap year - 1996 is not divisible by 400 (evenly at
- least) Besides that, anything divisible by 400 is divisible by 4, by
- definition. Martin's code will return a TRUE value for any number
- divisible by 4 (except 4000 and 100). The only qualifications I know if
- are these: must be between 1900 and 2100 (I may be wrong about the years)
- and be divisble by four (hopefully no debate there ;) ). In this case, the
- appropriate code would be:
-
- int IsLeap(int year)
- {
- if((year>1900) && (year<2100) && (year%4==0))
- return 1;
- else return 0;
- }
-
-
- : The following code will do it:
-
- : /* Return TRUE if iYear is a leap year, otherwise return FALSE */
-
- : int IsLeapYear(int iYear)
- : {
- : /* Check for a 4000th year */
- : if ( (iYear % 4000) == 0)
- : return FALSE;
-
- : /* Check for 400th year */
- : if ( (iYear % 400) == 0)
- : return TRUE;
-
- : /* Check for century */
- : if ( (iYear % 100) == 0 )
- : return FALSE;
-
- : /* C
- : if ( (iYear % 4) == 0 )
- : return TRUE;
-
- : return FALSE;
- : }
-
- : HTH.
-
- : |\/|
-
-
- --
- Ian Curtis (kato@monsoon.xnet.com - telnet xnet.com 8888)
- My opinions are most likely NOT those of the US Navy...
-